﻿package com.d4p.iterator
{
	internal class CollectionIterator implements IFIterator
	{
		private var idx:uint = new uint(0);
		private var collection:IFCollection;
		public function CollectionIterator(collection:IFCollection):void{
			this.collection = collection;
		}
		public function remove():*
		{
			var result:* = collection.removeItemAt(--this.idx);
			return result;
		}
		
		public function hasNext():Boolean
		{
			return this.idx < this.collection.getLength();
		}
		
		public function next():*
		{
			var result:* = collection.getItemAt(this.idx++);
			return result;
			
		}
		public function replaceWith(item:*):int
		{
			trace("current iterator idx : " , idx);
			return this.collection.replaceWith(item, this.idx-1);
		}
			
	}
}